<?php

/**
 * Framework_Component_OwnerNav
 *
 * @author      Ian Szewczyk <roamzero@gmail.com>
 * @copyright   (c) 2007 Ian Szewczyk. All rights reserved.
 * @license http://www.opensource.org/licenses/bsd-license.php
 * @package Framework
 * @subpackage Component
 * @filesource
 */

/**
 * Framework_Component_OwnerNav
 *
 *
 * @author Ian Szewczyk <roamzero@gmail.com>
 * @package Framework
 * @subpackage Component
 */

class Framework_Component_OwnerNav extends Framework_Component_Common
{
    
	/**
	 * __construct
	 *
	 * @access 		public
	 * @param 		array		$params		Parameters passed from template
	 * @return 		void
	 */
    public function __construct($params = null)
    {
        parent::__construct($params);
        $this->tplFile = null;
    }
    
    /**
	 * run
	 *
	 * @access 		public
	 * 
	 * @return 		void
	 */
    public function run()
    {
    	// Use Navigator class
		$navigator = new Framework_Navigator('','ownerTabs', 'ajaxTabs');
		
		$meta = Framework_Meta::factory();
		$metaTable = $meta->getTable();
		
		$queryArray = array(
			'sqlKey' => array(
				'select' => 'idMetaModule, moduleAlias',
				'where'  => 'moduleActive = 1 AND moduleCategory = "User"'
			)
		);
		
		$result = $metaTable->select($queryArray);
		
		if (!PEAR::isError($result) && count($result)) {
			
			foreach ($result as $row) {
				if ($row['idMetaModule'] == 'CP' && $this->user->userStatus == OWNER_USER_STATUS) {
					$navigator->setItem( $row['idMetaModule'] ,'/'.Framework::$request->ownerName.'/'.$row['idMetaModule'], $row['moduleAlias']); 
					
				} else if ($row['idMetaModule'] != 'CP') {
					$navigator->setItem( $row['idMetaModule'] ,'/'.Framework::$request->ownerName.'/'.$row['idMetaModule'], $row['moduleAlias']);
				}
					
				if (Framework::$module->moduleName == $row['idMetaModule'] && Framework::$module->className != 'CP') {
					$navigator->setActive($row['idMetaModule']);
				} else if (Framework::$module->className == 'CP') {
					$navigator->setActive('CP');
				}
				
			}
			
		}
		
		$navigator->setOrder(array('CP', 'Profile', 'People'));
		$this->setData('nav',$navigator->getNavigation());

    	
    	
    }

    /**
	 * buildMenu
	 *
	 * @access 		public
	 * 
	 * @return 		void
	 */
    private function buildMenu()
    {
    	
    	if ($module->presenter == 'Smarty') {
    		$modules = Framework_Conf::getConfig('peopletab', 'moduleRegistry');
    		$user = Framework_User::singleton();
	    	// Use Navigator class
	    	$navigator = new Framework_Navigator('/'.Framework::$site->ownerName.'/','ownerTabs');
    		foreach ($modules as $key => $value) {
    			if($value['level'] == 'owner'){
    				if ($key == 'CP' && $user->userStatus == OWNER_USER_STATUS) 
    					$navigator->setItem($key,$key);
    				elseif($key != 'CP')
    					$navigator->setItem($key,$key);
    				if ($module->moduleName == $key) $navigator->setActive($key);
    			}
    		}
    		
    		$this->setData('ownerNav',$navigator->getNavigation());
    	}
    	
    	
    }
}

?>